#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <graphics.h>
#include <math.h>
#include <bios.h>
#include <stdlib.h>

#define F "fly.wav"

void play(int sample)
{
	sound(abs(sample));
}

int fx,fy;
void main()
{
	long c=0,len;
	FILE *p;
	int x=0;
	int *buf;
	int gdriver=DETECT,gmode;
	initgraph(&gdriver,&gmode,"");
	fx=getmaxx();
	fy=getmaxy();
	p=fopen(F,"rb");
	if(!p) {
		printf("\nFailed to open file");
		return;
	}
	fseek(p,0,SEEK_END);
	len=ftell(p)-44;
	outtextxy(0,0,F);
	buf=(int *)malloc(len);
	fread(buf,sizeof(int),len/sizeof(int),p);
	getch();
	while(1) {
		for(c=0;c<len;c++) {
			putpixel((c*fx*8)/len,(fy/2)+buf[c]/(fy/2),15);
			if(bioskey(1)) {
				goto ext;
			}
		}
	}
	ext:
	nosound();
	fclose(p);
	closegraph();
}
